/**
 * 文件名：TaskBean.java
 * 
 * 版本信息：
 * 日期：2013-3-19
 * Copyright 足下 Corporation 2013
 * 版权所有
 * 
 */
package com.hugedata.cdn.service.task.bean;

import java.sql.Timestamp;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

import com.hugedata.cdn.service.util.TaskFieldChooseFilter;

/**
 * 项目名称：cdn 类名称：TaskBean 类描述： 创建人：zhaoaihua 创建时间：2013-3-19 下午4:16:57 修改备注：
 * 
 * @version
 */
public class TaskBean
{

    // 任务id
    private String taskID;

    // 用户ID
    private String userID;

    // 任务名称
    private String taskName;

    // 任务类型 1:测评
    private int taskType;

    private String urlName;

    private String taskUrl;

    private String cdnUrl;
    
    private String ip;

    private int taskPort;

    // 任务探测时间
    private int taskInterval;

    private Timestamp creatTime;

    private Timestamp startTime;

    private Timestamp endTime;

    private Timestamp cancelTime;

    // 任务状态（0：删除 1：正常 2：暂停）
    private int status;

    // 任务修改标示
    private int updateFalg;

    // cdn网站类型
    private int cdnId;

    private String imspTask;

    private String tasks;

    /** add by luxiumin /20110309 begin **/
    private String taskAccessType;
    private String taskNodeType;
    private String taskCycle;
    private int urlType;

    /** add by luxiumin /20110309 end **/

    public String getTasks()
    {
        return tasks;
    }

    public int getUrlType()
    {
        return urlType;
    }

    public void setUrlType(int urlType)
    {
        /**
         * urlType =1 单个资源
         * urlType = 2 域名
         */
        if (taskUrl.contains("000") || cdnUrl.contains("0"))
        {
            this.urlType = 1;
        }
        else
        {
            this.urlType = 2;
        }
    }

    public void setTasks()
    {
        tasks = taskUrl + ";" + cdnUrl;
    }

    public String findToolId()
    {
        String toolId = "00";
        if (1 == taskType)
        {
            // modify by luxiumin/20140311
            // 定义webtest工具ID
            toolId = "16";
        }
        return toolId;
    }

    public String getTaskAccessType()
    {
        return taskAccessType;
    }

    public void setTaskAccessType(String taskAccessType)
    {
        this.taskAccessType = taskAccessType;
    }

    public String getTaskNodeType()
    {
        return taskNodeType;
    }

    public void setTaskNodeType(String taskNodeType)
    {
        this.taskNodeType = taskNodeType;
    }

    public String getTaskCycle()
    {
        return taskCycle;
    }

    public void setTaskCycle(String taskCycle)
    {
        this.taskCycle = taskCycle;
    }

    public String getTaskID()
    {
        return taskID;
    }

    public void setTaskID(String taskID)
    {
        this.taskID = taskID;
    }

    public String getUserID()
    {
        return userID;
    }

    public void setUserID(String userID)
    {
        this.userID = userID;
    }

    public String getTaskName()
    {
        return taskName;
    }

    public void setTaskName(String taskName)
    {
        this.taskName = taskName;
    }

    public void setTaskPort(int taskPort)
    {
        this.taskPort = taskPort;
    }

    public int getTaskType()
    {
        return taskType;
    }

    public void setTaskType(int taskType)
    {
        this.taskType = taskType;
    }

    public int getTaskInterval()
    {
        return taskInterval;
    }

    public void setTaskInterval(int taskInterval)
    {
        this.taskInterval = taskInterval;
    }

    public int getUpdateFalg()
    {
        return updateFalg;
    }

    public void setUpdateFalg(int updateFalg)
    {
        this.updateFalg = updateFalg;
    }

    public int getStatus()
    {
        return status;
    }

    public void setStatus(int status)
    {
        this.status = status;
    }

    public String getUrlName()
    {
        return urlName;
    }

    public void setUrlName(String urlName)
    {
        this.urlName = urlName;
    }

    public String getTaskUrl()
    {
        return taskUrl;
    }

    public void setTaskUrl(String taskUrl)
    {
        this.taskUrl = taskUrl;
    }

    public String getCdnUrl()
    {
        return cdnUrl;
    }

    public void setCdnUrl(String cdnUrl)
    {
        this.cdnUrl = cdnUrl;
    }

    /**
     * @return ip
     */
    public String getIp()
    {
        return ip;
    }

    /**
     * @param ip 要设置的 ip
     */
    public void setIp(String ip)
    {
        this.ip = ip;
    }

    public Timestamp getCreatTime()
    {
        return creatTime;
    }

    public void setCreatTime(Timestamp creatTime)
    {
        this.creatTime = creatTime;
    }

    public Timestamp getStartTime()
    {
        return startTime;
    }

    public void setStartTime(Timestamp startTime)
    {
        this.startTime = startTime;
    }

    public Timestamp getEndTime()
    {
        return endTime;
    }

    public void setEndTime(Timestamp endTime)
    {
        this.endTime = endTime;
    }

    public Timestamp getCancelTime()
    {
        return cancelTime;
    }

    public void setCancelTime(Timestamp cancelTime)
    {
        this.cancelTime = cancelTime;
    }

    public int getCdnId()
    {
        return cdnId;
    }

    public void setCdnId(int cdnId)
    {
        this.cdnId = cdnId;
    }

    public int getTaskPort()
    {
        return taskPort;
    }

    public String toTaskJson(String[] fields)
    {
        // json属性选择
        // String[] fields = {
        // "taskID", "taskType", "taskHost", "taskPort", "taskInterval" };
        JsonConfig config = new JsonConfig();
        config.setJsonPropertyFilter(new TaskFieldChooseFilter(fields));
        return JSONObject.fromObject(this, config).toString();
    }

    public boolean equals(TaskBean anObject)
    {
        if (null == anObject)
        {
            return false;
        }

        return anObject.taskID.equalsIgnoreCase(this.taskID);
    }

    public static void main(String[] args)
    {
        TaskBean bean = new TaskBean();
        bean.setTaskID("11");
        // bean.setDnsServer("192.168.1.1");
        String[] fields =
        { "taskID", "taskType", "taskHost", "taskPort", "taskInterval" };
        System.out.println(bean.toTaskJson(fields));
    }

    public String getImspTask()
    {
        return imspTask;
    }

    public void setImspTask(String imspTask)
    {
        this.imspTask = imspTask;
    }

    @Override
    public String toString()
    {
        return "TaskBean [taskID=" + taskID + ", userID=" + userID + ", taskName=" + taskName + ", taskType="
                + taskType + ", urlName=" + urlName + ", taskUrl=" + taskUrl + ", cdnUrl=" + cdnUrl + ", taskPort="
                + taskPort + ", taskInterval=" + taskInterval + ", creatTime=" + creatTime + ", startTime=" + startTime
                + ", endTime=" + endTime + ", cancelTime=" + cancelTime + ", status=" + status + ", updateFalg="
                + updateFalg + ", cdnId=" + cdnId + ", imspTask=" + imspTask + ", tasks=" + tasks + ", taskAccessType="
                + taskAccessType + ", taskNodeType=" + taskNodeType + ", taskCycle=" + taskCycle + ", urlType="
                + urlType + "]";
    }
}
